package user

import (
	"gitee.com/gopher2011/go-zero-gva/internal/svc"
	"gitee.com/gopher2011/go-zero-gva/internal/types"
	"gitee.com/gopher2011/go-zero-gva/utils"
)

func (l *User) ChangePassword(req types.ChangePasswordReq) (*types.Response, error) {
	var user svc.SysUser
	if err := l.SvcCtx.DB.Where("username = ? and password = ?",req.Username,utils.MD5V([]byte(req.Password))).First(&user).Update("password",utils.MD5V([]byte(req.NewPassword))).Error;err !=nil {
		return &types.Response{
			Code: 7,
			Msg: "修改失败，原密码与当前账户不符",
			Data: nil,
		}, nil
	}
	return &types.Response{
		Code: 0,
		Msg: "修改成功",
		Data: nil,
	}, nil
}
// 接口测试
/*
Post /user/changePassword
{
   "username":"admin01",
	"password":"root001",
	"newPassword":"root002"
}

{
	"code": 0,
	"data": {},
	"msg": "修改成功"
}

{
	"code": 7,
	"data": {},
	"msg": "修改失败，原密码与当前账户不符"
}
*/

